package com.itsu.admin.mvc;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

/**
 * @author Jerry.Su
 * @Date 2021/12/31 16:50
 */
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result {

    public static final int SUCCESS_CODE = 0;

    public static final int ERROR_CODE = -1;

    private int code;
    private String msg;
    private Object data;


    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result() {
    }

    public static Result ok(String msg) {
        return new Result(SUCCESS_CODE, msg, null);
    }

    public static Result ok(Object data) {
        return new Result(SUCCESS_CODE, null, data);
    }

    public static Result ok() {
        return new Result(SUCCESS_CODE, null, null);
    }

    public static Result error(String msg) {
        return new Result(ERROR_CODE, msg, null);
    }

    public static Result error(int code) {
        return new Result(code, null, null);
    }

    public static Result error(int code, String msg) {
        return new Result(code, msg, null);
    }
}
